Skip to content

Add lazy loading in products list #18

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

yogeshpaliyal
Copy link
Contributor

@yogeshpaliyal yogeshpaliyal commented Aug 10, 2024

Fixes #17

Implement lazy loading in the AllProducts component to fetch more products when scrolling.

  • AllProducts.jsx

    • Add state variables lastVisible and isFetchingMore to manage pagination and loading state.
    • Update useEffect to fetch products in batches and set lastVisible.
    • Add a scroll event listener to fetch more products when the user scrolls to the bottom.
    • Update the fetchProduct function call to include pagination parameters.
    • Remove slicing of products array to display all fetched products.
  • productSlice.js

    • Update fetchProduct function to accept pagination parameters (startAfterDoc and limitCount).
    • Modify Firestore query to fetch products in batches using startAfter and limit.
    • Return the fetched products and the last visible product in the response.
    • Update the fetchProduct.fulfilled case to set state.items to the fetched products.

For more details, open the Copilot Workspace session.

Fixes bhagirathpaliyal#17

Implement lazy loading in the `AllProducts` component to fetch more products when scrolling.

* **AllProducts.jsx**
  - Add state variables `lastVisible` and `isFetchingMore` to manage pagination and loading state.
  - Update `useEffect` to fetch products in batches and set `lastVisible`.
  - Add a scroll event listener to fetch more products when the user scrolls to the bottom.
  - Update the `fetchProduct` function call to include pagination parameters.
  - Remove slicing of products array to display all fetched products.

* **productSlice.js**
  - Update `fetchProduct` function to accept pagination parameters (`startAfterDoc` and `limitCount`).
  - Modify Firestore query to fetch products in batches using `startAfter` and `limit`.
  - Return the fetched products and the last visible product in the response.
  - Update the `fetchProduct.fulfilled` case to set `state.items` to the fetched products.

---

For more details, open the [Copilot Workspace session](https://copilot-workspace.githubnext.com/bhagirathpaliyal/E-commerce-page/issues/17?shareId=XXXX-XXXX-XXXX-XXXX).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add Lazy Loading in Products list
1 participant